/*------------------------------------------------------
                hou_elearningGEN beta v1.0
Author: xtrung.net@gmail.com
Write On: 04/27/2008
Create On:4/13/2012 11:23:01 AM
------------------------------------------------------*/
using hou_elearning.DataAccess.Base;
using hou_elearning.Entity;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;

namespace hou_elearning.DataAccess
{    
    public class LienheDAL : SqlProvider<LienheEntity>
    {
        static LienheDAL()
        {
            InitReader();
        }
        protected static void InitReader()
        {
            getFromReader=delegate(SqlDataReader dr)
            {
                LienheEntity entity = new LienheEntity();
				entity.PK_iLienheID = Int64.Parse("0"+dr["PK_iLienheID"].ToString());
				entity.sNoidung = dr["sNoidung"].ToString();
				entity.dNgaygiolienhe =String.IsNullOrEmpty(dr["dNgaygiolienhe"].ToString())?DateTime.Now:DateTime.Parse(dr["dNgaygiolienhe"].ToString());
				entity.sEmail = dr["sEmail"].ToString();
                return entity;
            };
        }
        public static LienheEntity GetOne(Int64 PK_iLienheID)
        {
            string cmdName = "spLienhe_GetByPK";
            SqlParameter p = new SqlParameter("@PK_iLienheID", PK_iLienheID);
            LienheEntity entity = GetOne(cmdName, p);
            return entity;
        }
        public static List<LienheEntity> GetAll()
        {
            string cmdName = "spLienhe_Get";
            return GetList(cmdName);
        }
        
        public static int Add(LienheEntity entity)
        {
            string cmdName = "spLienhe_Insert";
            return Run(cmdName,true,initParams(entity));

        }
        public static bool Edit(LienheEntity entity)
        {
            string cmdName = "spLienhe_Update";
            return Run(cmdName,false,initParams(entity))>0;
        }
        public static bool Remove(Int64 PK_iLienheID)
        {
            string cmdName = "spLienhe_Delete";
            SqlParameter p = new SqlParameter("@PK_iLienheID", PK_iLienheID);
            return Run(cmdName,false,p)>0;
        }
        #region private
        private static SqlParameter[] initParams(LienheEntity entity)
        {
            SqlParameter[] p = new SqlParameter[4];
			p[0] = new SqlParameter("@PK_iLienheID", entity.PK_iLienheID);
			p[1] = new SqlParameter("@sNoidung", entity.sNoidung);
			p[2] = new SqlParameter("@dNgaygiolienhe", entity.dNgaygiolienhe);
			p[3] = new SqlParameter("@sEmail", entity.sEmail);
            return p;
        }
        #endregion
       
    }
}